<template>
  <div class="GBSite">
    <filterPanel filterName="GBSiteFilter" filterTitle="合作站点关联查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GBSiteTable" :tableLoading="loading" tableTitle="合作站点关联列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "GBSite",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '合作站点名称',
						name: 'company_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						name: 'organization_code',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人身份证',
						name: 'legal_card_no',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '收/寄件时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					company_name: '',
					organization_code: '',
					legal_person: '',
					legal_phone: '',
					legal_card_no: '',
					time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '合作站点名称',
						width: 180,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 200,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						width: 120,
						name: 'legal_person',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						width: 160,
						name: 'legal_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人身份证号',
						width: 200,
						name: 'legal_card_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
					{
						title: '接触电话数',
						width: 120,
						name: 'emp_num',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'receive',
								name: '收件详情'
							},
							{
								type: 'send',
								name: '寄件详情'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					field: 'judge_action_id',
					company_name: this.form.company_name,
					organization_code: this.form.organization_code,
					legal_person: this.form.legal_person,
					legal_phone: this.form.legal_phone,
					legal_card_no: this.form.legal_card_no,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_created_time = this.form.time[0] / 1000;
					data.end_created_time = this.form.time[1] / 1000;
				}
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.g_getCooperRiskReport, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.receive = true;
							item.send = true
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.tableData = []
						this.total = 0;
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				switch (type) {
					case 'receive':
						this.$toRoutePath({
							path: "/receive_list",
							edit: true,
							query: {}
						});
						break;
					case 'send':
						this.$toRoutePath({
							path: "/logistics_list",
							edit: true,
							query: {}
						});
						break;
				}
			},
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/abDataStatistics/personnel/index.less">

</style>
